package org.oimwrapper.connectors.internal;

import com.thortech.xl.orb.dataaccess.*;
import java.sql.*;

/**
 * JDBC meta data interface into OIM.
 * 
 * THIS IS AN INTERNAL CLASS AND SHOULD NOT BE USED DIRECTLY.
 */
public class OIMDBMetaData implements ResultSetMetaData {
	
	protected tcColumn[] metaData;
	
	/**
	 * Default Constructor;
	 * 
	 * @param MetaData The meta data from the OIM result set.
	 */
	public OIMDBMetaData(tcColumn[] MetaData) {
		metaData = MetaData;
	}

	/**
	 * This method is not supported.
	 * 
	 * @exception SQLException
	 */
	public String getCatalogName(int Index) throws SQLException {
		throw new UnsupportedOperationException("Not supported.");
	}

	/**
	 * This method is not supported.
	 * 
	 * @exception SQLException
	 */
	public String getColumnClassName(int Index) throws SQLException {
		throw new UnsupportedOperationException("Not supported.");
	}

	/**
	 * Gets the number of columns.
	 * 
	 * @return The number of columns
	 * @exception SQLException
	 */
	public int getColumnCount() throws SQLException {
		return metaData.length;
	}

	/**
	 * This method is not supported.
	 * 
	 * @exception SQLException
	 */
	public int getColumnDisplaySize(int Index) throws SQLException {
		throw new UnsupportedOperationException("Not supported.");
	}

	/**
	 * Gets the description for a column.
	 * 
	 * @param Index The index of the column.
	 * @return The description for a column.
	 * @exception SQLException
	 */
	public String getColumnLabel(int Index) throws SQLException {
		return metaData[Index].isDescription;
	}

	/**
	 * Gets the name for a column.
	 * 
	 * @param Index The index of the column.
	 * @return The name for a column.
	 * @exception SQLException
	 */
	public String getColumnName(int Index) throws SQLException {
		return metaData[Index].isName;
	}

	/**
	 * Gets the type for a column.
	 * 
	 * @param Index The index of the column.
	 * @return The type for a column.
	 * @exception SQLException
	 */
	public int getColumnType(int Index) throws SQLException {
		return metaData[Index].inSqlType;
	}

	/**
	 * Gets the type for a column.
	 * 
	 * @param Index The index of the column.
	 * @return The type for a column.
	 * @exception SQLException
	 */
	public String getColumnTypeName(int Index) throws SQLException {
		switch (getColumnType(Index)) {
			case Types.BOOLEAN:
				return "boolean";
			case Types.CHAR:
				return "char";
			case Types.DATE:
				return "date";
			case Types.DECIMAL:
				return "decimal";
			case Types.DOUBLE:
				return "double";
			case Types.FLOAT:
				return "float";
			case Types.INTEGER:
				return "integer";
			case Types.NUMERIC:
				return "number";
			case Types.SMALLINT:
				return "short";
			case Types.VARCHAR:
				return "string";
			default:
				return "unknown";
		}
	}

	/**
	 * Gets the precision for a column.
	 * 
	 * @param Index The index of the column.
	 * @return The precision for a column.
	 * @exception SQLException
	 */
	public int getPrecision(int Index) throws SQLException {
		return metaData[Index].inPrecision;
	}

	/**
	 * Gets the scale for a column.
	 * 
	 * @param Index The index of the column.
	 * @return The scale for a column.
	 * @exception SQLException
	 */
	public int getScale(int Index) throws SQLException {
		return metaData[Index].inScale;
	}

	/**
	 * This method is not supported.
	 * 
	 * @exception SQLException
	 */
	public String getSchemaName(int Index) throws SQLException {
		throw new UnsupportedOperationException("Not supported.");
	}

	/**
	 * This method is not supported.
	 * 
	 * @exception SQLException
	 */
	public String getTableName(int Index) throws SQLException {
		throw new UnsupportedOperationException("Not supported.");
	}

	/**
	 * This method is not supported.
	 * 
	 * @exception SQLException
	 */
	public boolean isAutoIncrement(int Index) throws SQLException {
		throw new UnsupportedOperationException("Not supported.");
	}

	/**
	 * This method is not supported.
	 * 
	 * @exception SQLException
	 */
	public boolean isCaseSensitive(int Index) throws SQLException {
		throw new UnsupportedOperationException("Not supported.");
	}

	/**
	 * This method is not supported.
	 * 
	 * @exception SQLException
	 */
	public boolean isCurrency(int Index) throws SQLException {
		throw new UnsupportedOperationException("Not supported.");
	}

	/**
	 * Indicates if the column is writable.
	 * 
	 * @param Index The index of the column.
	 * @return <code>false</code> None of the records can be updated.
	 * @exception SQLException
	 */
	public boolean isDefinitelyWritable(int Index) throws SQLException {
		return false;
	}

	/**
	 * This method is not supported.
	 * 
	 * @exception SQLException
	 */
	public int isNullable(int Index) throws SQLException {
		throw new UnsupportedOperationException("Not supported.");
	}

	/**
	 * Indicates if the column is read-only.
	 * 
	 * @param Index The index of the column.
	 * @return <code>true</code> None of the records can be updated.
	 * @exception SQLException
	 */
	public boolean isReadOnly(int Index) throws SQLException {
		return true;
	}

	/**
	 * Indicates if the column is searchable.
	 * 
	 * @param Index The index of the column.
	 * @return <code>true</code> The results can be manually searched
	 * @exception SQLException
	 */
	public boolean isSearchable(int Index) throws SQLException {
		return true;
	}

	/**
	 * This method is not supported.
	 * 
	 * @exception SQLException
	 */
	public boolean isSigned(int Index) throws SQLException {
		throw new UnsupportedOperationException("Not supported.");
	}

	/**
	 * Indicates if the column is writable.
	 * 
	 * @param Index The index of the column.
	 * @return <code>false</code> None of the records can be updated.
	 * @exception SQLException
	 */
	public boolean isWritable(int Index) throws SQLException {
		return false;
	}

    @Override
    public <T> T unwrap(Class<T> iface) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public boolean isWrapperFor(Class<?> iface) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}